package com.osi.mes.qm.services;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Hashtable;
import java.util.Vector;

import pnuts.lang.Context;

import com.datasweep.compatibility.client.ATDefinition;
import com.datasweep.compatibility.client.ATHandler;
import com.datasweep.compatibility.client.ATRow;
import com.datasweep.compatibility.client.ATRowFilter;
import com.datasweep.compatibility.client.DatasweepException;
import com.datasweep.compatibility.client.DependentATRow;
import com.datasweep.compatibility.client.ParentATRow;
import com.datasweep.compatibility.client.Response;
import com.datasweep.compatibility.ui.Time;
import com.osi.mes.base.BaseService;
import com.osi.mes.qm.base.constants.IATComingMat;
import com.rockwell.ftpc.framework.common.StringUtils;

public class QmComingMatChkService extends BaseService implements IATComingMat
{

	public QmComingMatChkService(Context context)
	{
		super(context);
	}

	// 通过检验名称，检验类别，检验标准类别查询检验项目
	public Vector<?> getMatChkItem(String chkType, String chkStType, String chkItemName)
		throws DatasweepException
	{
		String atDefName = IATComingMat.AT_MAT_CHK_ITEMS;
		ATHandler atHandler = getFunctions().createATHandler(
			atDefName);
		ATRowFilter rowFilter = getFunctions().createATRowFilter(
			atDefName);
		if (StringUtils.isNotNull(chkType))
			rowFilter.forColumnNameEqualTo(
				MAT_CHK_TYPE, chkType);

		if (StringUtils.isNotNull(chkStType))
			rowFilter.forColumnNameEqualTo(
				MAT_CHK_STANDARD_TYPE, chkStType);

		if (StringUtils.isNotNull(chkItemName))
			rowFilter.forColumnNameEqualTo(
				MAT_CHK_ITEM_NAME, chkItemName);

		Vector<?> matcheChkItems = atHandler.getATRowsByFilter(
			rowFilter, false);
		return matcheChkItems;
	}

	// 通过主键查询检验项目
	public ATRow getMatChkItem(String chkItemKey)
		throws DatasweepException
	{
		// Hashtable<String,Object> hashTb = new Hashtable<String,Object>();
		// if(StringUtils.isNotNull(chkItemKey))
		// hashTb.put(MAT_CHK_ITEM_KEY,chkItemKey);
		// Vector<?> res= super.getATRowData(AT_MAT_CHK_ITEMS, hashTb);
		// if(res!=null && res.size()>0)
		// return (ATRow)res.get(0);

		String atDefName = AT_MAT_CHK_ITEMS;
		ATRowFilter atRowFilt = getFunctions().createATRowFilter(
			atDefName);

		if (StringUtils.isNotNull(chkItemKey))
			atRowFilt.forColumnNameEqualTo(
				MAT_CHK_ITEM_KEY, chkItemKey);
		Vector<?> res = super.getATRows(atRowFilt);

		if (res != null && res.size() > 0)
			return (ATRow) res.get(0);
		return null;
	}

	// 通过主键查询规格检验的数据
	public Vector<?> searchSpecChkATRowsByChkTbNo(String chkTbNo)
		throws DatasweepException
	{
		Hashtable<String, Object> hashTb = new Hashtable<String, Object>();
		if (StringUtils.isNotNull(chkTbNo))
			hashTb.put(
				"chk_tb_no", chkTbNo);
		Vector<?> res = super.getATRowData(
			"QMRawMatSpcChk", hashTb);

		return res;
	}

	// 查询检验项目配置的历史记录
	public Vector<?> searchChkItemMdHistories(String chkType, String chkStType,
		Time actionTimeFrom, Time actionTimeTo, String actionUser)
		throws DatasweepException
	{
		String atDefName = "osi_base_QMMatChkMdHistory";
		ATHandler atHandler = getFunctions().createATHandler(
			atDefName);
		ATRowFilter rowFilter = getFunctions().createATRowFilter(
			atDefName);

		if (StringUtils.isNotNull(chkType))
			rowFilter.forColumnNameEqualTo(
				"chk_type", chkType);

		if (StringUtils.isNotNull(chkStType))
			rowFilter.forColumnNameEqualTo(
				"chk_st_type", chkStType);
		if (actionTimeFrom != null)
		{
			actionTimeFrom = super.getDayStart(actionTimeFrom);
			rowFilter.forColumnNameGreaterThanOrEqualTo(
				"md_time", actionTimeFrom);
		}
		if (actionTimeTo != null)
		{
			actionTimeTo = super.getDayEnd(actionTimeTo);
			rowFilter.forColumnNameLessThan(
				"md_time", actionTimeTo);
		}

		if (StringUtils.isNotNull(actionUser))
		{
			rowFilter.forColumnNameEqualTo(
				"md_user", actionUser);
		}

		Vector<?> matcheHistories = atHandler.getATRowsByFilter(
			rowFilter, false);
		return matcheHistories;
	}

	// 通过检验项目主键，删除检验项目
	public void deleteHisByChkItemKey(String chkItemKey)
		throws DatasweepException
	{
		String atDefName = "osi_base_QMMatChkMdHistory";
		ATHandler atHandler = getFunctions().createATHandler(
			atDefName);
		ATRowFilter rowFilter = getFunctions().createATRowFilter(
			atDefName);

		if (StringUtils.isNotNull(chkItemKey))
		{
			rowFilter.forColumnNameEqualTo(
				"chk_item_key", chkItemKey);
		}

		Vector<?> matcheHistories = atHandler.getATRowsByFilter(
			rowFilter, false);
		if (matcheHistories == null || matcheHistories.size() <= 0)
			return;

		for (int i = 0; i < matcheHistories.size(); i++)
		{
			ATRow his = (ATRow) matcheHistories.get(i);
			super.deleteAtRow(his);
		}

	}

	// 保存标准限额配置
	public ATRow saveMatChkConfig(ATRow matChkRel, Object[] data)
		throws DatasweepException
	{
		String atDefName = AT_MAT_CHK_REL;
		ATHandler atHandler = getFunctions().createATHandler(
			atDefName);

		if (matChkRel == null)
		{
			matChkRel = atHandler.createATRow();
		}
		else
		{
			removeDeptATRows((ParentATRow) matChkRel);
		}

		matChkRel.setValue(
			AT_MAT_CHK_ST_TYPE, data[5]);
		matChkRel.setValue(
			AT_MAT_CHK_TYPE_NAME, data[4]);
		matChkRel.setValue(
			AT_MAT_CHK_CONFIG_ITEM_KEY, super.getSerialNum());
		matChkRel.setValue(
			AT_MAT_CHK_MAT_NAME, data[1]);
		matChkRel.setValue(
			AT_MAT_CHK_USING_MAT_CONFIG, data[0]);
		matChkRel.setValue(
			AT_MAT_CHK_USING_VENDOR, data[2]);
		matChkRel.setValue(
			AT_MAT_CHK_VENDOR_NAME, data[3]);

		Response response = super.saveATRow(matChkRel);
		if (response.isOk())
		{
			ParentATRow pATRow = (ParentATRow) matChkRel;

			Object chkItemObj = data[6];
			if (chkItemObj instanceof Object[])
			{
				Object[] chkItems = (Object[]) chkItemObj;
				ATDefinition deptDef = getFunctions().getATDefinition(
					AT_MAT_CHK_CONFIG_ITEMS);
				for (int i = 0; i < chkItems.length; i++)
				{
					Object obj = chkItems[i];
					String chkItem = obj != null ? obj.toString() : null;
					if (chkItem == null)
						continue;

					Vector<?> atRows = getMatChkItem(
						data[4].toString(), data[5].toString(), chkItem);
					if (atRows != null && atRows.size() > 0)
					{
						ATRow atRow = (ATRow) atRows.get(0);
						if (atRow == null)
							continue;

						Response res = pATRow.createDependentATRow(
							deptDef, null);
						if (res.isOk())
						{
							DependentATRow deptATRow = (DependentATRow) res.getResult();
							deptATRow.setValue(
								AT_MAT_CHK_ITEM_KEY, atRow.getValue(MAT_CHK_ITEM_KEY));
							deptATRow.setValue(
								AT_MAT_CHK_ITEM_NAME, chkItem);
							deptATRow.setValue(
								AT_MAT_CHK_STANDARD, atRow.getValue(MAT_CHK_ITEM_ST));
							deptATRow.setValue(
								AT_MAT_CHK_NORMAL_DEFECT, atRow.getValue(MAT_CHK_NORMAL_DEFECT));
							deptATRow.setValue(
								AT_MAT_CHK_SERIOUS_DEFECT, atRow.getValue(MAT_CHK_SERIOUS_DEFECT));
						}
					}
				}

				response = super.saveATRow(pATRow);
				return pATRow;
			}
		}

		return null;
	}

	public DependentATRow getMatChkConfigItem(String chkItemKey, ParentATRow matChkRel)
	{
		if (matChkRel == null || chkItemKey == null)
			return null;

		Vector<?> deptAtRows = matChkRel.getDependentATRows();
		if (deptAtRows == null || deptAtRows.size() == 0)
			return null;

		for (int i = 0; i < deptAtRows.size(); i++)
		{
			if (deptAtRows.get(i) instanceof DependentATRow)
			{
				DependentATRow deptATRow = (DependentATRow) deptAtRows.get(i);

				String itemKey = (String) deptATRow.getValue(AT_MAT_CHK_ITEM_KEY);
				if (chkItemKey.equals(itemKey))
					return deptATRow;
			}
		}

		return null;
	}

	public boolean removeDeptATRows(ParentATRow matChkRel)
		throws DatasweepException
	{
		if (matChkRel == null)
			return false;

		Vector<?> deptAtRows = matChkRel.getDependentATRows();
		if (deptAtRows == null || deptAtRows.size() == 0)
			return false;

		for (int i = 0; i < deptAtRows.size(); i++)
		{
			if (deptAtRows.get(i) instanceof DependentATRow)
			{
				DependentATRow deptATRow = (DependentATRow) deptAtRows.get(i);
				matChkRel.removeDependentATRow(deptATRow);
			}
		}

		return true;
	}

	// 查询原辅料接收单
	public Vector<?> serachRawAccMatRecTbs(String recId, String vendorName, String partNumber,
		String partDesc, Time storeStTime, Time storeEndTime, boolean isAcc)
		throws DatasweepException
	{
		Vector<ATRow> res = new Vector<ATRow>();

		String atDefName = AT_RAW_ACC_MAT_REC_CHK;
		ATHandler atHandler = getFunctions().createATHandler(
			atDefName);
		ATRowFilter rowFilter = getFunctions().createATRowFilter(
			atDefName);

		if (StringUtils.isNotNull(recId))
		{
			rowFilter.forColumnNameContaining(
				RAW_ACC_REC_TB_NO, recId);
		}

		if (StringUtils.isNotNull(vendorName))
		{
			rowFilter.forColumnNameContaining(
				RAW_ACC_VENDOR_NAME, vendorName);
		}

		if (storeStTime != null)
		{
			rowFilter.forColumnNameGreaterThanOrEqualTo(
				RAW_ACC_REC_DATE, super.getDayStart(storeStTime));

		}

		if (storeEndTime != null)
		{
			rowFilter.forColumnNameLessThan(
				RAW_ACC_REC_DATE, super.getDayEnd(storeEndTime));
		}

		if (isAcc == true)
		{
			rowFilter.forColumnNameEqualTo(
				RAW_ACC_MAT_TYPE, 1);
		}
		else
		{
			rowFilter.forColumnNameEqualTo(
				RAW_ACC_MAT_TYPE, 0);
		}

		Vector<?> recTbs = atHandler.getATRowsByFilter(
			rowFilter, false);
		if (recTbs == null)
			return res;
		for (int i = 0; i < recTbs.size(); i++)
		{
			ParentATRow parentAtRow = (ParentATRow) recTbs.get(i);
			Vector dependentATRows = parentAtRow.getDependentATRows();
			for (int j = 0; j < dependentATRows.size(); j++)
			{
				DependentATRow dependentATRow = (DependentATRow) dependentATRows.get(j);
				if (dependentATRow != null)
				{
					String partNum = (String) dependentATRow.getValue(RAW_ACC_REC_MAT_ID);
					String partDes = (String) dependentATRow.getValue(RAW_ACC_REC_MAT_NAME);
					if (StringUtils.isNull(partNumber) && StringUtils.isNull(partDesc))
					{
						res.add(parentAtRow);
						break;
					}
					if (StringUtils.isNotNull(partNumber))
					{
						if (partNum.indexOf(partNumber) > -1)
						{
							res.add(parentAtRow);
							break;
						}
					}
					if (StringUtils.isNotNull(partDesc))
					{
						if (partDes.indexOf(partDesc) > -1)
						{
							res.add(parentAtRow);
							break;
						}
					}
				}
			}
		}
		return res;
	}

	// 查询检验单，通过主键
	public ATRow searchChkTb(String key, String atDefName)
		throws DatasweepException
	{
		if (StringUtils.isNull(key))
			return null;

		ATHandler atHandler = getFunctions().createATHandler(
			atDefName);
		ATRowFilter rowFilter = getFunctions().createATRowFilter(
			atDefName);
		rowFilter.forColumnNameEqualTo(
			"chk_tb_no", key);

		Vector<?> res = atHandler.getATRowsByFilter(
			rowFilter, false);

		if (res != null && res.size() > 0)
			return (ATRow) res.get(0);

		return null;
	}

	// 查询检验单
	public Vector<?> searchChkTbsByRecTbNo(String recLotNo, String chkResult, String matName,
		Time relTime)
		throws DatasweepException
	{
		String atDefName = "QMRawMatChkTb";
		ATHandler atHandler = getFunctions().createATHandler(
			atDefName);
		ATRowFilter rowFilter = getFunctions().createATRowFilter(
			atDefName);

		if (StringUtils.isNotNull(recLotNo))
		{
			rowFilter.forColumnNameEqualTo(
				"rec_lot", recLotNo);
		}

		if (StringUtils.isNotNull(chkResult))
		{
			if (chkResult.equals("合格"))
			{
				rowFilter.forColumnNameEqualTo(
					"chk_result", true);
			}
			else if (chkResult.equals("不合格"))
			{
				rowFilter.forColumnNameEqualTo(
					"chk_result", false);
			}
		}

		if (StringUtils.isNotNull(matName))
		{
			rowFilter.forColumnNameEqualTo(
				"mat_name", matName);
		}

		if (relTime != null)
		{
			rowFilter.forColumnNameGreaterThanOrEqualTo(
				"realse_date", super.getDayStart(relTime));
			rowFilter.forColumnNameLessThan(
				"realse_date", super.getDayStart(relTime.addDays(1)));
		}

		Vector<?> atRows = atHandler.getATRowsByFilter(
			rowFilter, false);

		return atRows;
	}

	// 查询物料的检验项目配置： 供应商，物料，检验标准类别
	public Vector<?> serachChkItems(String vendorName, String matName, String chkStType,
		String chkType)
		throws DatasweepException
	{
		Vector<?> allItems = searchChkItemsByVendor(
			vendorName, chkStType, chkType);
		if (allItems != null && allItems.size() > 0)
			return allItems;

		return searchChkItemsByMat(
			matName, chkStType, chkType);
	}

	public Vector<?> searchChkItemsByVendor(String vendorName, String chkStType, String chkType)
		throws DatasweepException
	{
		if (StringUtils.isNull(vendorName))
			return new Vector();

		Hashtable<String, Object> hashTb = new Hashtable<String, Object>();
		hashTb.put(
			AT_MAT_CHK_VENDOR_NAME, vendorName);
		hashTb.put(
			AT_MAT_CHK_USING_VENDOR, true);
		if (StringUtils.isNotNull(chkStType))
			hashTb.put(
				AT_MAT_CHK_ST_TYPE, chkStType);

		if (StringUtils.isNotNull(chkType))
			hashTb.put(
				AT_MAT_CHK_TYPE_NAME, chkType);

		return super.getATRowData(
			AT_MAT_CHK_REL, hashTb);
	}

	public Vector<?> searchChkItemsByMat(String matName, String chkStType, String chkType)
		throws DatasweepException
	{
		if (StringUtils.isNull(matName))
			return new Vector();

		Hashtable<String, Object> hashTb = new Hashtable<String, Object>();
		hashTb.put(
			AT_MAT_CHK_MAT_NAME, matName);
		hashTb.put(
			AT_MAT_CHK_USING_MAT_CONFIG, true);

		if (StringUtils.isNotNull(chkType))
			hashTb.put(
				AT_MAT_CHK_TYPE_NAME, chkType);

		if (StringUtils.isNotNull(chkType))
			hashTb.put(
				AT_MAT_CHK_TYPE_NAME, chkType);

		return super.getATRowData(
			AT_MAT_CHK_REL, hashTb);
	}

	public Vector<?> searchInOutSourceRecTbs(String recId, String vendorName, String partNumber,
		String partDesc, Time recStDate, Time recEndDate,
		int sourceType)
		throws DatasweepException
	{
		String atDefName = IN_OUT_SOURCE_REC_CHK;

		Vector<ATRow> res = new Vector<ATRow>();

		ATHandler atHandler = getFunctions().createATHandler(
			atDefName);
		ATRowFilter rowFilter = getFunctions().createATRowFilter(
			atDefName);

		if (StringUtils.isNotNull(recId))
		{
			rowFilter.forColumnNameContaining(
				IN_OUT_SOURCE_REC_TB_NO, recId);
		}

		if (StringUtils.isNotNull(vendorName))
		{
			rowFilter.forColumnNameContaining(
				IN_OUT_SOURCE_VENDOR_NAME, vendorName);
		}

		if (recStDate != null)
		{
			rowFilter.forColumnNameGreaterThanOrEqualTo(
				IN_OUT_SOURCE_REC_DATE, super.getDayStart(recStDate));
		}

		if (recEndDate != null)
		{
			rowFilter.forColumnNameLessThan(
				IN_OUT_SOURCE_REC_DATE, super.getDayEnd(recEndDate));
		}

		if (sourceType > -1)
		{
			rowFilter.forColumnNameEqualTo(
				IN_OUT_SOURCE_MAT_TYPE, sourceType);
		}

		Vector<?> recTbs = atHandler.getATRowsByFilter(
			rowFilter, false);
		if (recTbs == null)
			return res;
		for (int i = 0; i < recTbs.size(); i++)
		{
			ParentATRow parentAtRow = (ParentATRow) recTbs.get(i);
			Vector dependentATRows = parentAtRow.getDependentATRows();
			for (int j = 0; j < dependentATRows.size(); j++)
			{
				DependentATRow dependentATRow = (DependentATRow) dependentATRows.get(j);
				if (dependentATRow != null)
				{
					String partNum = (String) dependentATRow.getValue(IN_OUT_SOURCE_MAT_ID);
					String partDes = (String) dependentATRow.getValue(IN_OUT_SOURCE_MAT_NAME);
					if (StringUtils.isNull(partNumber) && StringUtils.isNull(partDesc))
					{
						res.add(parentAtRow);
						break;
					}
					if (StringUtils.isNotNull(partNumber))
					{
						if (partNum.indexOf(partNumber) > -1)
						{
							res.add(parentAtRow);
							break;
						}
					}
					if (StringUtils.isNotNull(partDesc))
					{
						if (partDes.indexOf(partDesc) > -1)
						{
							res.add(parentAtRow);
							break;
						}
					}
				}
			}
		}
		return res;

	}

	public Vector<?> searchChemicalProdRecTbs(String recId, String vendorName, String partNumber,
		String partDesc, Time recStDate, Time recEndDate)
		throws DatasweepException
	{
		String atDefName = CHEMICAL_PROD_CHK;

		Vector<ATRow> res = new Vector<ATRow>();

		ATHandler atHandler = getFunctions().createATHandler(
			atDefName);
		ATRowFilter rowFilter = getFunctions().createATRowFilter(
			atDefName);

		if (StringUtils.isNotNull(recId))
		{
			rowFilter.forColumnNameContaining(
				CHEMICAL_PROD_REC_TB_NO, recId);
		}

		if (StringUtils.isNotNull(vendorName))
		{
			rowFilter.forColumnNameContaining(
				CHEMICAL_PROD_VENDOR_NAME, vendorName);
		}
		
		if (StringUtils.isNotNull(vendorName))
		{
			rowFilter.forColumnNameEqualTo(
				CHEMICAL_PROD_VENDOR_NAME, vendorName);
		}

		if (recStDate != null)
		{
			rowFilter.forColumnNameGreaterThanOrEqualTo(
				CHEMICAL_PROD_REC_DATE, super.getDayStart(recStDate));
		}

		if (recEndDate != null)
		{
			rowFilter.forColumnNameLessThan(
				CHEMICAL_PROD_REC_DATE, super.getDayEnd(recEndDate));
		}

		Vector<?> recTbs = atHandler.getATRowsByFilter(
			rowFilter, false);
		if (recTbs == null)
			return res;
		for (int i = 0; i < recTbs.size(); i++)
		{
			ParentATRow parentAtRow = (ParentATRow) recTbs.get(i);
			Vector dependentATRows = parentAtRow.getDependentATRows();
			for (int j = 0; j < dependentATRows.size(); j++)
			{
				DependentATRow dependentATRow = (DependentATRow) dependentATRows.get(j);
				if (dependentATRow != null)
				{
					String partNum = (String) dependentATRow.getValue(CHEMICAL_PROD_MAT_ID);
					String partDes = (String) dependentATRow.getValue(CHEMICAL_PROD_MAT_NAME);
					if (StringUtils.isNull(partNumber) && StringUtils.isNull(partDesc))
					{
						res.add(parentAtRow);
						break;
					}
					if (StringUtils.isNotNull(partNumber))
					{
						if (partNum.indexOf(partNumber) > -1)
						{
							res.add(parentAtRow);
							break;
						}
					}
					if (StringUtils.isNotNull(partDesc))
					{
						if (partDes.indexOf(partDesc) > -1)
						{
							res.add(parentAtRow);
							break;
						}
					}
				}
			}
		}
		return res;
	}

	public boolean viewPictures(String url)
	{
		URI uri;
		boolean isSucc = true;
		try
		{
			uri = new URI(url);
			Desktop.getDesktop().browse(
				uri);
		}
		catch (URISyntaxException e)
		{
			// TODO Auto-generated catch block
			isSucc = false;
			e.printStackTrace();
		}
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			isSucc = false;
			e.printStackTrace();
		}

		return isSucc;
	}

	// 查询检验单
	public Vector<?> searchChkTbs(Time createStTime, Time createEndTime, String auditResult,
		String type, String vendor)
		throws DatasweepException
	{
		String atDefName = "";
		int matType = -1;
		if ("原料检验单".equals(type))
		{
			// 原料，辅料
			atDefName = IATComingMat.AT_RAW_ACC_MAT_CHK;
			matType = 0;
		}
		else if ("辅料检验单".equals(type))
		{
			// 原料，辅料
			atDefName = IATComingMat.AT_RAW_ACC_MAT_CHK;
			matType = 1;
		}

		else if ("内包材检验单".equals(type))
		{
			// 内外包材
			atDefName = IATComingMat.AT_IN_OUT_SOURCE_CHK;
			matType = 1;
		}
		else if ("外包材检验单".equals(type))
		{
			// 内外包材
			atDefName = IATComingMat.AT_IN_OUT_SOURCE_CHK;
			matType = 0;

		}
		else if ("化学品检验单".equals(type))
		{
			// 化学品
			atDefName = IATComingMat.AT_CHEMICAL_PROD_CHK;
		}

		ATRowFilter atRowFilt = getFunctions().createATRowFilter(
			atDefName);

		if (StringUtils.isNotNull(auditResult))
		{
			Boolean isQua = true;
			if ("合格".equals(auditResult))
			{
				isQua = true;
			}
			else if ("不合格".equals(auditResult))
			{
				isQua = false;
			}
			else
			{
				isQua = null;
			}

			atRowFilt.forColumnNameEqualTo(
				"chk_result", isQua);
		}

		if (createStTime != null)
		{
			atRowFilt.forCreatedTimeGreaterThanOrEqualTo(getDayStart(createStTime));
		}

		if (createEndTime != null)
		{
			atRowFilt.forCreatedTimeLessThan(getDayEnd(createEndTime));
		}

		if (matType > -1)
		{
			atRowFilt.forColumnNameEqualTo(
				"mat_type", matType);
		}

		if (StringUtils.isNotNull(vendor))
		{
			atRowFilt.forColumnNameEqualTo(
				"vendor_name", vendor);
		}

		return getATRows(atRowFilt);
	}

	// 通过接收单编号查询接收单
	public ATRow searchRecTbByNo(String recTbNo, String type)
		throws DatasweepException
	{
		String atDefName = "";
		if ("原料检验单".equals(type) || "辅料检验单".equals(type))
		{
			// 原料，辅料
			atDefName = IATComingMat.AT_RAW_ACC_MAT_REC_CHK;
		}
		else if ("内包材检验单".equals(type) || "外包材检验单".equals(type))
		{
			// 内外包材
			atDefName = IATComingMat.IN_OUT_SOURCE_REC_CHK;
		}
		else if ("化学品检验单".equals(type))
		{
			// 化学品
			atDefName = IATComingMat.CHEMICAL_PROD_CHK;
		}

		if (StringUtils.isNull(atDefName))
			return null;

		ATRowFilter atRowFilt = getFunctions().createATRowFilter(
			atDefName);
		atRowFilt.forColumnNameEqualTo(
			"recTbNo", recTbNo);

		Vector<ATRow> atRows = super.getATRows(atRowFilt);
		if (atRows != null && atRows.size() > 0)
			return atRows.get(0);

		return null;
	}

}
